package whyusethem;

import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: gia
 * Date: 30.08.2012
 * Time: 00:00
 *
 */
public class UsingGenericsInstead {
    public static void main(String[] args) {

        List<Integer> luckyNumbers = getMyLuckyNumbers();

        addSomethingToList(luckyNumbers,"");

        //addSomethingToObjectList(luckyNumbers,"");

        System.out.println(sumLuckyNumbers(luckyNumbers));

    }



    private static int sumLuckyNumbers(List<Integer> luckyNumbers) {
        int sum = 0;

        for (Integer luckyNumber : luckyNumbers) {
            sum += luckyNumber;
        }

        return sum;
    }


    private static List<Integer> getMyLuckyNumbers() {

        List<Integer> luckyNumbers = new LinkedList<Integer>();
        luckyNumbers.add(4);
        luckyNumbers.add(6);
        luckyNumbers.add(13);

        return luckyNumbers;

    }

    private static void addSomethingToList(List list, Object something) {

        list.add(something);

    }

    private static void addSomethingToObjectList(List<Object> list, Object something) {

        list.add(something);

    }

    private static void doSomethingWithListOfAnything(List<?> list){

        for(Object obj:list){
            System.out.println(obj);
        }
    }

}
